﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <script src="../JS/layer/layer.m.js"></script>
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>
    <script src="../JS/mobiscroll.zepto.js"></script>
    <script src="../JS/mobiscroll.core.js"></script>
    <script src="../JS/mobiscroll.scroller.js"></script>
    <script src="../JS/mobiscroll.datetime.js"></script>
    <script src="../JS/mobiscroll.i18n.zh.js"></script>
    <link href="../JS/Date/FT_Date.min.css" rel="stylesheet" />
    <script src="../JS/jquery.autoTextarea.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });

        var height = 0;
        var width = 0;
        var strId = "";
        //var jq = $.noConflict();
        var currYear = (new Date()).getFullYear();
        var opt = {
            date: { preset: 'date' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    //model.ctData.RBDate = valueText;
                }
            }
        };
        function fun1(str) {
            $("#kssj").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);
        }
        function fun2(str) {
            $("#jssj").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);
        }

        var model = avalon.define({
            $id: "qjmodel",
            code: "CCXJ",
            lg: "",
            sh: "",
            ptype: "0",
            wximg: "",
            rdm: Math.random(),
            ctData: { "LeiBie": "", "StarTime": "", "EndTime": "", "Daycount": 1, "ZhuYaoShiYou": "", "ChaoSongRen": "", "Files": "","intProcessStanceid":"" },
            savedata: function () {
                if (model.ctData.LeiBie == "") {
                    $.tips({
                        content: "请选择假别",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.StarTime =="") {
                    $.tips({
                        content: "请输入开始时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.EndTime == "") {
                    $.tips({
                        content: "请输入结束时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.StarTime > model.ctData.EndTime)
                {
                    $.tips({
                        content: "开始时间大于结束时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.Daycount == "") {
                    $.tips({
                        content: "请输入请假天数",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (isNaN(model.ctData.Daycount) || model.ctData.Daycount==0) {
                    $.tips({
                        content: "请假天数输入错误",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }

                if (model.ctData.ZhuYaoShiYou=="") {
                    $.tips({
                        content: "请输入请假事由",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                model.lg = $.loading({
                    content: '保存中...',
                })

                psmodel.savedata();
                
            },
            repshow: function () {
                $(this).parent().siblings().removeClass("active");
                $(this).parent().addClass("active");
            },
            selperson: function () {
                $("#content").hide();
                $("#iframep").show();

                var cheight = height;
                var cwidth = width;

                $("#iframep").css("height", cheight);
                $("#iframep").css("width", cwidth);

            },
            bjk: function () {

                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:' + (width - 76) + 'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入请假事由">' + model.ctData.ZhuYaoShiYou + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.ZhuYaoShiYou = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#hdjj").addClass("ui-txt-muted");
                            $("#hdjj").html("请输入请假事由");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
                $("#hdjjbjk").focus();
            }

        });

        function goback() {
            $("#content").show();
            $("#iframep").hide();
        }
        function goconfirm(json) {
            if (json != null) {
                $("#kh_fzry").removeClass("ui-txt-muted");
                $("#kh_fzry").html(json.vuser);
                model.ctData.ChaoSongRen = json.vusername;
            }
            else {
                $("#kh_fzry").addClass("ui-txt-muted");
                $("#kh_fzry").html('请选择抄送人');
                model.ctData.ChaoSongRen = '';
            }

            $("#content").show();
            $("#iframep").hide();
        }

        function getpiid(piid) {
            model.ctData.intProcessStanceid = piid;
        }

        function Sava()
        {
            if (!model.ctData.intProcessStanceid) {
                model.lg.hide();
                $.tips({
                    content: "保存失败",
                    stayTime: 2000,
                    type: "warn"
                })
            }
            else {
                model.ctData.Files = "";
                $("#imglist .tpli").each(function () {
                    if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                        if (model.wximg) {
                            model.wximg += ",";
                        }
                        model.wximg += $(this).attr("itemid");

                    } else {
                        if (model.ctData.Files) {
                            model.ctData.Files = model.ctData.Files + ',' + $(this).attr("itemid");
                        }
                        else {
                            model.ctData.Files = $(this).attr("itemid");
                        }
                    }

                })
                $.post("/API/WXAPI.ashx?Action=ADDCCQJ&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model), P2: model.wximg }, function (data) {
                    model.lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $("button").hide();
                        var el = $.tips({
                            content: "保存成功！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {
                            //window.location.reload();
                            window.location.replace(location.href);
                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                    }
                })
            }
        }

        avalon.ready(function () {
            width = document.documentElement.clientWidth;
            height = document.documentElement.clientHeight;
            model.lg = $.loading({
                content: '加载中...',
            })
            fun1(new Date(new Date().setDate(new Date().getDate() + 1)));
            fun2(new Date(new Date().setDate(new Date().getDate() + 1)));
            model.ctData.StarTime = $("#kssj").val();
            model.ctData.EndTime = $("#jssj").val();
            $.post("/API/WXAPI.ashx?Action=GETCOLUMNLIST&r="+Math.random(), { "P1": "3" }, function (data) {
                
                var data = $.parseJSON(data);
                if (data.ErrorMsg == "") {
                    $("#leibie").empty();
                    for (var i = 0; i < data.Result.length; i++) {
                        $("#leibie").append('<option value="' + data.Result[i].TypeNO + '">' + data.Result[i].TypeNO + '</option>');
                        if (i == 0) {
                            model.ctData.LeiBie = data.Result[i].TypeNO;
                        }
                    }
                }
                else {
                    $.tips({
                        content: "假别加载失败，原因：" + data.ErrorMsg,
                        stayTime: 2000,
                        type: "warn"
                    })
                }

                setTimeout("load()", 500);
                
            })
            
            $("#iframep").attr("src", "UI_PERSON.html?r=" + Math.random());
            $(".chackTextarea-area").autoTextarea({
                maxHeight: 220,
                minHeight: 80
            });
            MobileCom.uploadimg();
        })
        function back() {
            window.location.replace("UI_QJCC_LIST.html?r=" + Math.random());
        }
    </script>
    <style type="text/css">
        .ui-select {
            border: none;
            border: 0;
            background-color: #fff;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }
        .ms-controller, [ms-controller] {
            display: none;
        }
        .ui-form-item .wspan {
            width: 100%;
            display: -webkit-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }

            .ui-form-item .wspan img {
                width: 50px;
                height: 50px;
                padding-right: 3px;
            }

        .sctp {
            color: #18b4ed;
            right: 4px;
            top: -5px;
            z-index: 9;
            width: 20px;
            height: 20px;
            background: #fff;
            border-radius: 13px;
            line-height: 20px;
            text-indent: -3px;
            position: absolute;
            font-size: 25px;
        }

        .imgxl {
            position: relative;
            float: left;
            padding-top: 0;
            height: 50px;
            width: 50px;
            padding-right: 10px;
            margin-left: 0px;
            margin-bottom: 5px;
        }

        .tpxs {
            height: 50px;
            width: 50px;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
            background-repeat: no-repeat;
            -webkit-background-size: cover;
        }
    </style>
    <title>请假出差</title>
</head>
<body ms-controller="qjmodel">
    <div id="content">
        <!--<div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg ui-btn-primary" ms-click="savedata()">
                新增请假出差
            </button>
        </div>-->
        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg" onclick="back()">
                取消
            </button>
            <button class="ui-btn-lg ui-btn-primary" id="save" ms-click="savedata()">
                新增请假
            </button>
        </div>
        <section class="ui-container">
            <div class="ui-form ui-border-t">
                <div class="ui-form-item ui-border-b">
                    <label>
                        假别
                    </label>
                    <div class="ui-select ui-border-b">
                        <select ms-duplex="ctData.LeiBie" id="leibie"></select>
                    </div>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        开始时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="请输入开始时间" ms-duplex="ctData.StarTime" id="kssj" style="padding-left:0" />
                    </div>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        结束时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="请输入结束时间" ms-duplex="ctData.EndTime" id="jssj" style="padding-left:0" />
                    </div>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        请假天数
                    </label>
                    <input type="tel" placeholder="请输入请假天数" ms-duplex="ctData.Daycount" />
                </div>
                <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;min-height:44px">
                    <label>
                        请假事由
                    </label>
                    <textarea placeholder="请输入请假事由" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.ZhuYaoShiYou"></textarea>
                    <!--<div class="ui-txt-muted ui-whitespace" style="padding-left: 95px;text-align:justify" id="hdjj" ms-click="bjk()">请输入请假事由</div>-->
                    <!--<input type="text" placeholder="请输入请假事由" ms-duplex="ctData.ZhuYaoShiYou" />-->
                </div>
                <!--<div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        抄送人
                    </label>
                    <div class="ui-txt-muted ui-whitespace ui-form-item-link" style="padding-left: 95px;text-align:justify" id="kh_fzry" ms-click="selperson()">请选择抄送人</div>

                </div>-->

                <!--<iframe id="ifp" src="UI_PROCESS.html?CODE=CCXJ" style="border: 0; height: 44px"></iframe>-->

                <div ms-include-src="UI_PROCESS.html?r={{rdm}}">

                </div>

                <div class="ui-form-item ui-border-b" style="height:auto;min-height:44px">
                    <label>
                        上传图片
                    </label>

                    <div class="wspan" style="padding-top: 5px; height: auto;display:block">
                        <ul id="imglist">
                            <li class="imgxl scli"><img id="add_pit" src="../Images/icon-add.png" /></li>
                        </ul>
                        <div style="clear:both"></div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <iframe id="iframep" src="UI_PERSON.html" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>
</body>
</html>
